#pragma once

#include "LockQueue.h"

#include <string>

#define LOG_INFO_(msgformat, ...)                            \
    do                                                       \
    {                                                        \
        Logger_ &logger = Logger_::GetInstance();            \
        logger.SetLevel(INFO_);                              \
        char buf[1024];                                      \
        snprintf(buf, sizeof buf, msgformat, ##__VA_ARGS__); \
        std::string msg("[INFO_ ]");                         \
        msg += buf;                                          \
        logger.Log(msg);                                     \
    } while (0)

#define LOG_ERROR_(msgformat, ...)                           \
    do                                                       \
    {                                                        \
        Logger_ &logger = Logger_::GetInstance();            \
        logger.SetLevel(ERROR_);                             \
        char buf[1024];                                      \
        snprintf(buf, sizeof buf, msgformat, ##__VA_ARGS__); \
        std::string msg("[ERROR_]");                         \
        msg += buf;                                          \
        logger.Log(msg);                                     \
    } while (0)

enum Level
{
    INFO_ = 1,
    ERROR_
};

// 日志系统，单例模式
class Logger_
{
public:
    static Logger_ &GetInstance();
    // 设置日志级别
    void SetLevel(Level level);
    // 写日志
    void Log(std::string msg);

private:
    Logger_();
    Logger_(const Logger_ &) = delete;
    Logger_ &operator=(const Logger_ &) = delete;

    int m_loglevel;                  // 日志级别
    LockQueue<std::string> m_lckQue; // 日志缓冲队列
};
